package com.woniu.mgr.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniu.mgr.common.Result;
import com.woniu.mgr.model.Article;
import com.woniu.mgr.model.Coach;
import com.woniu.mgr.service.ArticleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 文章表 前端控制器
 * </p>
 *
 * @author Silas
 * @since 2023-02-15
 */
@RestController
@RequestMapping("/article")
@Slf4j
@Api(tags = "文章查询及修改")
public class ArticleController {

    @Resource
    private ArticleService articleService;

    @GetMapping("/articleSee")
    @ApiOperation("文章分页查询")
    public Result articleSee(Integer page, Integer size) {
        log.info("执行了分页查询操作 {}{}", page, size);
        IPage<Article> list = articleService.list(page, size);
        return Result.success(200, "查询成功", list);
    }

    @DeleteMapping("/articleDelete/{id}")
    @ApiOperation("删除文章")
    public Result articleDelete(@PathVariable Integer id) {
        log.info("执行了文章删除操作 {}", id);
        articleService.removeById(id);
        return Result.success(200, "删除成功", null);
    }


    @GetMapping("/query")
    public Result query(String condition, Integer current, Integer size) {
        log.info("查看所有文章");
        Page<Article> query = articleService.query(condition, current, size);
        return Result.success(200, "查询成功", query);
    }


}

